package com.sqly.doc.util;

import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

/**
 * Author：袁从斌 on 2018/4/16 15:11
 * <p>
 * 功能描述:单例吐司
 */
public class ToastUtil {
    private ToastUtil(){}

    private static Toast sToast;

    /**
     * 单例短时间的Toast
     * @param context
     * @param message
     */
    public static void showShortToast(Context context, String message){
        if (sToast==null){
            sToast = Toast.makeText(context.getApplicationContext(),"", Toast.LENGTH_SHORT);
        }
        sToast.setText(message);
        sToast.show();
    }

    /**
     * 单例长吐司
     * @param context
     * @param message
     */
    public static void showLongToast(Context context, String message){
        if (sToast==null){
            sToast = Toast.makeText(context.getApplicationContext(),"", Toast.LENGTH_LONG);
        }
        sToast.setText(message);
        sToast.show();
    }

    /**
     * 单例中间显示的吐司
     * @param context
     * @param message
     */
    public static void showCenterToast(Context context, String message){
        if (sToast==null){
            sToast = Toast.makeText(context.getApplicationContext(),"", Toast.LENGTH_SHORT);
        }
        sToast.setGravity(Gravity.CENTER,0,0);
        sToast.show();
    }
}
